#!/usr/bin/env python
# -*- coding: utf-8 -*-

import random
import string
import shutil
from pathlib import Path

work_dir = Path('/home/liuwei/test')

def create_file():
    sub_dir = Path('a/b/c/d')
    (work_dir / sub_dir).mkdir(parents=True, exist_ok=True)
    file_lst = [''.join(random.choices(string.ascii_lowercase, k=4)) for i in range(50)]
    lst_dirs = list(sub_dir.parents)[:-1] + [sub_dir]
    for file in file_lst:
        (work_dir / random.choice(lst_dirs) / file).touch()

def ignore(src, names):
    ig = {name for name in names if name[0] not in {'x','y','z'} and (Path(src) / name).is_file()}
    return set(ig)

def main():
    src = work_dir / 'a'
    dst = work_dir / 'dst'
    shutil.rmtree(work_dir)
    create_file()
    shutil.copytree(src, dst, ignore=ignore)
    
if __name__=='__main__':
    main()


# 做得不错
